/*
 * @Author: yangrongxin
 * @Date: 2021-08-18 11:16:00
 * @LastEditors: liubin
 * @LastEditTime: 2021-10-21 17:44:38
 */
import { STORAGE_TYPE } from '@/const/dataDictionary';
import request, { Request } from '@/restful/index';
import requestFn from '@/utils/request';
import { getItemSync } from '@/utils/storage';

const defaultEnv = SHOW_TEST_TOOLS === 'true' && getItemSync(STORAGE_TYPE.DEBUGGER_HOST)?.MINI_PROGRAM_STATE_ENV;

// 修改支付接口的请求地址
let requestAddress = 'https://pttestapi.cd120.info/cloud';
if (defaultEnv === 'staging') {
  requestAddress = 'https://hxgyapipre.cd120.info/cloud';
}
if (defaultEnv === 'production') {
  requestAddress = 'https://hxgyapiv2.cd120.info/cloud';
}

/* 根据订单id获取测评记录详情数据 */
export const getParamsWithOrderId = async (data: any) => request(Request.Order.getParamsWithOrderId, data);

/* 根据传入的参数 请求支付接口 */
export const getPayParams = async (data: any) => {
  const { openId = '' } = getItemSync('userInfo') || {};
  const { bizSysSeq, dealSeq, merchantSeq } = data;
  return requestFn(
    `${requestAddress}/paygateway/weixin/unifiedOrder?merchantSeq=${merchantSeq}&bizSysSeq=${bizSysSeq}&dealSeq=${dealSeq}&dealType=WXAPP&openid=${openId}`,
    {},
  );
};

/* 校验当前的支付状态 */
export const checkPayStatus = async (data: any): Promise<any> => {
  const { bizSysSeq, dealSeq } = data;
  return requestFn(`${requestAddress}/paygateway/checkPayStatus?bizSysSeq=${bizSysSeq}&dealSeq=${dealSeq}`, {});
};
